def input_passwd():
    pwd = input("请输入密码：")
    if len(pwd) >= 8:
        return pwd
    print("主动抛出异常")
    ex = Exception("密码长度小于8")
    raise ex

try:
    pwd = input_passwd()
    print(pwd)
except Exception as e:
    print(e)


def assert_exception():
    try:
        assert 1 == 2, '你的程序出现了该错误'   # 相当于if-raise
    except Exception as e:
        print(e)

if __name__ == '__main__':
    assert_exception()